<template>
	<view class="content">
		<view class="justify-between align-center bgWhite userinfo">
			<text>报名人信息</text>
			<text>{{name}}({{phone}})</text>
		</view>
        <view class="" style="background-color: #F3F7FA;height: 24rpx;">
        	
        </view>
            <view class="bgWhite radius8 plr15 ptb15 justify-between align-center mt12 info" >
                <image :src="$domain.api+detail.img_url" mode=""></image>
                <view class="flex1 flex-col justify-around" style="height: 180rpx;">
                        <view class="name ft16">{{detail.title}}</view>
						<text class="address ft12 ">时间：{{detail.start_date}}</text>
                        <text class="address ft12 ">地点：{{detail.address}}</text>
                </view>
            </view>
				
			<view class="Maindata">
				<view class="justify-between align-center ft16"  >
					<view class="">
						{{detail.title}}
					</view>
					<text class="mr25 ml20">*1</text>
					<text>￥{{detail.unitprice}}</text>
				</view>
				<view class="address ft15 mt10 " style="color: #666666;">时间：{{detail.start_date}}</view>
				<view class="address ft15 mt10 " style="color: #666666;">地点：{{detail.address}}</view>
			</view>
           
        <view class=" bgWhite paybtn">
           
            <view class="justify-between align-center">
                <view class="freebtn" v-if="Number(detail.unitprice)>0"> 
                合计金额： <text>￥</text><text style="font-size: 44rpx;">{{detail.unitprice }}</text> 
                </view>
               
                <view @click="pay" class="onlinePay">去支付</view>
            </view>
          
            
        </view>
		
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
                imgList:[],
                id:"",
                detail:{},
                current:0,
                openid:"",
				form:{},
				userInfo:uni.getStorageSync('userInfo'),
				orderId:"",
				actId:"",
				name:"",
				phone:""
			}
		},
		
		onLoad(opt) {
               if(opt.orderId) this.orderId = opt.orderId
			   if(opt.actId) this.actId = opt.actId
			   if(opt.name) this.name = opt.name
			   if(opt.phone) this.phone = opt.phone
			   
			   this.getDetail()
                // this.$refs.choseCoupon.open()
		},
		methods: {
				
			getDetail(){
				this.$api.getActDetails({
					id: this.actId
					
				}).then(res=>{
					this.detail = res.data
					console.log(res)
				})
				
			},
				showchosePop(){
					this.$refs.choseCoupon.open()
				},
				userCoupon(item){
					if(item.id==this.coupon_id){
							this.coupon_id=0
							this.couponPrice='请选择' 
						
					}else{
						this.coupon_id=item.id
						this.couponPrice='减'+item.min_amount+'元'
					}
				
					this.$refs.choseCoupon.close()
					
					
				},	
			async getMain() {
                const {data,code}  =   await this.$api.venueDetail({id:this.id })
                if(code==200){
                    this.detail = data
                }
			},
            async getTime() {
                const {data,code}  =    await this.$api.venueOpenTime({venueId:this.id})
                if(code==200){
                    console.log(data)
                    this.timeInfo = data[this.current]
                    
                }
            },
			async getCoupon(){
					const data =await this.$api.usedCoupon({user_id:this.userInfo.id,pay_amount:this.timeInfo.pay_fee}) 
					console.log(data)
					// this.yyData = data.data
			},
			async getOrderStatus(orderno){
				const data =await this.$api.checkOrder({out_trade_no:orderno})
				if(data.code==200){
					uni.navigateTo({
						url:'/pages/orderDetail/index?id='+orderno
					})
				}
				
			},
            async pay(){
				let vm =this
				vm.$api.orderPay({
					openid: uni.getStorageSync('userInfo').openid,		
					orderId:vm.orderId,
					actId:vm.actId,
					payFee:vm.detail.unitprice
				}).then(res => {
					uni.requestPayment({
						"provider": "wxpay",
						"appId": res.config.appId, // 微信开放平台 - 应用 - AppId，注意和微信小程序、公众号 AppId 可能不一致
						"nonceStr": res.config.nonceStr, // 随机字符串
						"package": res.config.package, // 固定值
						signType: res.config.signType,
						paySign: res.config.paySign,
						"timeStamp": res.config.timeStamp, // 时间戳（单位：秒）
						"sign": res.config.paySign, // 签名，这里用的 MD5/RSA 签名
				
						success(data) {
							uni.redirectTo({
								url:`/pages/orderSuccess/index?actId=${vm.actId}&orderno=${res.out_trade_no}&name=${vm.name}&phone=${vm.phone}`
							})
							vm.$api.checkOrder({orderno:res.out_trade_no}).then(res=>{
								
							})
						},
						fail(e) {
							console.log(e)
						}
					})
				})	
                
                
            }
		}
	}
</script>
<style scoped lang="scss">

 
    .paybtn{
        
        position: fixed;
        bottom: 0;
        width: 100%;
        padding: 30rpx;
        background-color: #fff;
		border-top: 2rpx solid #D8D8D8;
        .onlinePay{
            width: 312rpx;
            height: 86rpx;
            background: #FFFFFF;
            border-radius: 60rpx ;
            background: #0368FF;
            font-size: 32rpx;
            color: #fff;
            line-height: 86rpx;
            
            
            text-align: center;
        }
            
        .freebtn{
            text{
                color: #FA5151;
            }
        }
      
    }
 
    .Maindata{
		margin-top: 30rpx;
		border-top: 2rpx solid #D8D8D8;
		border-bottom: 2rpx solid #D8D8D8;
		padding: 58rpx 28rpx;
	}
 
    .info{
        image{
            width: 240rpx;
            height: 160rpx;
            
            margin-right: 40rpx;
        }
        .name{
            color: #3D3D3D;
            font-weight: 500;
        }
            
        .address{
            color: #9F9F9F;
        }
    }
  
	
	.userinfo{
		height: 100rpx;
		padding: 0 30rpx;
	}
</style>